package week_4;

public class ComparableRListNode<E extends Comparable<E>>
{
	E data_;
	
	ComparableRListNode<E> next_;
	
	public ComparableRListNode(E data, ComparableRListNode<E> next)
	{
		data_ = data;
		next_ = next;
	}
	
	@Override
	public String toString()
	{
		if (next_ == null)
		{
			return data_.toString();
		}
		else
		{
			return data_.toString() + " -> " + next_.toString();
		}
	}
	
	public void add(ComparableRListNode<E> data)
	{
		if (next_ == null)
		{
			next_ = data;
		}
		else if (data.data_.compareTo(next_.data_) < 0)
		{
			data.next_ = next_;
			next_ = data;
		}
		else
		{
			next_.add(data);
		}
	}
	
	public void delete(ComparableRListNode<E> data)
	{
		if (next_ != null)
		{
			if (next_.data_.equals(data.data_))
			{
				next_ = next_.next_;
			}
			else
			{
				next_.delete(data);
			}
		}
	}
}
